﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Fis.Win.Forms
{
    public partial class BalanceReportForm : ReportBaseForm
    {
        public BalanceReportForm()
        {
            InitializeComponent();
            theGridControl = gridControl1;

            InitializeBinding();
            InitializeViewUI();
            theGridControl = gridControl1;
        }

        public override void InitializeViewUI()
        {
            iView.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            iFilter.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            iChangeRange.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

            for (var i = 0; i < gridView1.VisibleColumns.Count; i++)
            {
                var col = gridView1.VisibleColumns[i];

                col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

                if (i == 1 || i == 5)
                {
                    col.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                }

                if (resetColumns.Contains(i))
                {
                    col.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
                }
            }

            gridView1.BestFitColumns();

            BindingRange();

            iChangeRange.EditValue = CurrentRange = int.Parse(Fis.Win.Utils.AppSession.Range);
        }

        protected override DataTable InitializeSchema()
        {
            resetColumns = new int[] { 2, 3, 6, 7 };

            var schema = "assembly://Agile.Engine.Config/Agile.Engine.Config.Schema/Balance_"
                + Fis.Win.Utils.AppSession.Book["FACCSYSTEM"].ToString() + ".xml";

            var stream = Agile.Engine.Utils.IOUtils.InputStream(schema);

            DataTable data = new DataTable();
            data.ReadXml(stream);
            return data;
        }

        protected override Fis.Win.Utils.ReportUtils InitializeData(DataTable dt)
        {
            return new Utils.ReportUtils(dt, CurrentRange);
        }

        protected override void ChangeRange(int Range)
        {
            base.ChangeRange(Range);

            if (Range == Fis.Win.Utils.AppSession.BookStartTime.Month)
                gridView1.ViewCaption = string.Format("{0}\t[会计期间：{1}期]", Text, "初始化");
            else
                gridView1.ViewCaption = string.Format("{0}\t[会计期间：{1}期]", Text, Range - 1);

            InitializeBinding();
        }
    }
}
